package com.bw.lib_common.coroutine

import android.util.Log
import kotlinx.coroutines.*
import java.util.concurrent.Executors

object CoroutineHelper {
    //协程的本质就是线程和线程池
    //协程异常处理器
    private val handle = CoroutineExceptionHandler { coroutineContext, throwable ->
        Log.e("Error", "Ex: " + throwable.message)
    }

    val myModelScope = CoroutineScope(Dispatchers.IO + SupervisorJob() + handle)

    //自定义协程调度器
    val mDispatcher1 = Executors.newFixedThreadPool(8).asCoroutineDispatcher()

    //单线程的协程调度器
    val mDispatcher2 = newSingleThreadContext("SingleThread")

    //固定大小的协程调度器
    val mDispatcher3 = newFixedThreadPoolContext(8, "FixedThread")
}